﻿Public Partial Class UserResetPassword
    Inherits BaseUserControl

    Public ReadOnly Property RequestedUsername() As String
        Get
            If Request.QueryString("username") IsNot Nothing Then
                Return Request.QueryString("username").ToString
            Else
                Return ""
            End If
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Overrides Sub Rebind()

    End Sub

    Protected Sub btnResetPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetPassword.Click
        Try

            If Not Membership.EnablePasswordReset Then
                Me.Prompt("The provider settinge does not allow to reset password!", UserControlPromptTypes.Alert)
                Exit Sub
            End If

            Dim membershipUser As MembershipUser = Membership.GetUser(Me.RequestedUsername)

            Dim newPassword As String
            If txtPasswordAnswer.Text.Length = 0 Then
                newPassword = membershipUser.ResetPassword
            Else
                newPassword = membershipUser.ResetPassword(txtPasswordAnswer.Text)
            End If

            Me.Prompt("Password has been set to: " & newPassword, UserControlPromptTypes.Successful)

        Catch ex As Exception
            Me.RaiseError(ex)
        End Try
    End Sub

End Class